import 'package:built_collection/built_collection.dart';
import 'package:mobile_app.core/core/domain/entities/learning_content/lexical_item/lexical_item.dart';
import 'package:mobile_app.core/core/domain/services/image_service/service.dart';
import 'package:mobile_app.home.menu.settings/image_settings_page/domain/helpers/get_all_image_download_task_id/helper.dart';
import 'package:mobile_app.home.menu.settings/image_settings_page/domain/helpers/get_all_image_ids/helper.dart';

abstract class DownloadAllImages {
  void call({
    required BuiltMap<String, LexicalItem> lexicalItemMap,
  });
}

class DownloadAllImagesImpl implements DownloadAllImages {
  const DownloadAllImagesImpl({
    required GetAllImageDownloadTaskId getAllImageDownloadTaskId,
    required GetAllImageIds getAllImageIds,
    required ImageService imageService,
  })  : _getAllImageDownloadTaskId = getAllImageDownloadTaskId,
        _getAllImageIds = getAllImageIds,
        _imageService = imageService;

  final GetAllImageDownloadTaskId _getAllImageDownloadTaskId;
  final GetAllImageIds _getAllImageIds;
  final ImageService _imageService;

  @override
  void call({
    required BuiltMap<String, LexicalItem> lexicalItemMap,
  }) {
    final allImageIds = _getAllImageIds(
      lexicalItemMap: lexicalItemMap,
    );

    final downloadTaskId = _getAllImageDownloadTaskId();

    _imageService.addDownloadTask(
      imageIds: allImageIds,
      taskId: downloadTaskId,
    );
  }
}
